package com.mysoft.gfyx.clue.controller;

import com.mysoft.framework.rpc.annotation.PubAction;
import com.mysoft.framework.rpc.annotation.PubService;
import com.mysoft.framework.rpc.contants.RequestPrefix;
import com.mysoft.gfyx.clue.controller.dto.GetSubsStatResponseDto;
import com.mysoft.gfyx.clue.service.OpptySubsService;
import com.mysoft.gfyx.clue.service.dto.OpptySubsDto;
import com.mysoft.sdk.common.exception.BusinessLogicException;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.util.UUID;

//商机订阅控制器
@PubService(value = "/opptySubsDataApi", prefix = RequestPrefix.API)
@Tag(name = "商机订阅-API")
public class OpptySubsDataApiController {

    @Resource
    private OpptySubsService opptysubsService;

    /**
     * 保存商机订阅
     */
    @PubAction(value = "/saveOpptySubs", method = RequestMethod.POST)
    public UUID saveOpptySubs(@RequestBody OpptySubsDto saveOpptySubsDto) {
        UUID uuid = opptysubsService.saveOpptySubs(saveOpptySubsDto);
        return uuid;
    }

    /**
     * 获取商机订阅名称列表 废弃
     */
//    @PubAction(value = "/getSubsNameList", method = RequestMethod.GET)
//    public List<GetSubsNameListResponseDto> getSubsNameList(Integer subsType) {
//        List<SubsNameDto> subsNameList = opptysubsService.getSubsNameList(subsType);
//        System.out.println("subsNameList===="+ subsNameList);
//        List<GetSubsNameListResponseDto> subsNameListResponseDto = MappingUtil.getSimpleMapperFacade().mapAsList(subsNameList, GetSubsNameListResponseDto.class);
//        return subsNameListResponseDto;
//    }

    /**
     * 获取商机订阅统计
     */
    @PubAction(value = "/getSubsStat", method = RequestMethod.POST)
    public GetSubsStatResponseDto getSubsStat() {
        GetSubsStatResponseDto getSubsStatResponseDto = new GetSubsStatResponseDto();
        getSubsStatResponseDto.setSubsMaximum(OpptySubsService.SUBS_MAXIMUM);
        int subsCount = opptysubsService.getSubsCount();
        getSubsStatResponseDto.setSubsCount(subsCount);
//        getSubsStatResponseDto.setRemainSubsCount(this.SUBS_MAXIMUM - subsCount);
        return getSubsStatResponseDto;
    }

    /**
     * 启用停用
     */
    @PubAction(value = "/enable", method = RequestMethod.POST)
    public boolean enable(UUID opptySubsGUID, int enable) {
        return opptysubsService.enable(opptySubsGUID, enable);
    }

    /**
     * 删除
     */
    @PubAction(value = "/delete", method = RequestMethod.POST)
    public boolean delete(UUID opptySubsGUID) throws BusinessLogicException {
        return opptysubsService.delete(opptySubsGUID);
    }

    /**
     * 获取商机订阅详情
     */
    @PubAction(value = "/getOne", method = RequestMethod.POST)
    public OpptySubsDto getOne(UUID opptySubsGUID) throws BusinessLogicException {
//        if (opptySubsGUID.toString().equals("")) {
//            throw new BusinessLogicException("opptySubsGUID不能为空");
//        }
        return opptysubsService.getOne(opptySubsGUID);
    }
}
